package edison.persistence;

import java.util.List;

import javax.jcr.nodetype.NodeDefinition;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderColumn;
import javax.persistence.Table;

import edison.utils.Converter;

@Entity(name = "NodeDefinition")
@Table(name = "NodeDefinition")
public class NodeDefinitionBean {
	@Id
	private String name;
	private boolean isAutoCreated;
	private boolean isMandatory;
	private int onParentVersionAction;
	private boolean isProtected;
	@ManyToOne(targetEntity = NodeTypeBean.class)
	private String declaringNodeType;

	@ManyToMany(targetEntity = NodeTypeBean.class)
	@OrderColumn
	protected List<String> requiredPrimaryTypeNames;

	@ManyToOne(targetEntity = NodeTypeBean.class)
	protected String defaultPrimaryTypeName;

	protected boolean isAllowsSameNameSiblings;

	public NodeDefinitionBean() {
	}

	public NodeDefinitionBean(NodeDefinition nd) {
		this.name = nd.getName();
		this.isAutoCreated = nd.isAutoCreated();
		this.isMandatory = nd.isMandatory();
		this.onParentVersionAction = nd.getOnParentVersion();
		this.isProtected = nd.isProtected();
		// this.declaringNodeType = nd.getDeclaringNodeType();
		List<String> requiredPrimaryTypeNames = Converter.toList(nd.getRequiredPrimaryTypeNames());
		this.requiredPrimaryTypeNames = requiredPrimaryTypeNames;
		this.defaultPrimaryTypeName = nd.getDefaultPrimaryTypeName();
		this.isAllowsSameNameSiblings = nd.allowsSameNameSiblings();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isAutoCreated() {
		return isAutoCreated;
	}

	public void setAutoCreated(boolean isAutoCreated) {
		this.isAutoCreated = isAutoCreated;
	}

	public boolean isMandatory() {
		return isMandatory;
	}

	public void setMandatory(boolean isMandatory) {
		this.isMandatory = isMandatory;
	}

	public int getOnParentVersionAction() {
		return onParentVersionAction;
	}

	public void setOnParentVersionAction(int onParentVersionAction) {
		this.onParentVersionAction = onParentVersionAction;
	}

	public boolean isProtected() {
		return isProtected;
	}

	public void setProtected(boolean isProtected) {
		this.isProtected = isProtected;
	}

	public String getDeclaringNodeType() {
		return declaringNodeType;
	}

	public void setDeclaringNodeType(String declaringNodeType) {
		this.declaringNodeType = declaringNodeType;
	}

	public List<String> getRequiredPrimaryTypeNames() {
		return requiredPrimaryTypeNames;
	}

	public void setRequiredPrimaryTypeNames(List<String> requiredPrimaryTypeNames) {
		this.requiredPrimaryTypeNames = requiredPrimaryTypeNames;
	}

	public String getDefaultPrimaryTypeName() {
		return defaultPrimaryTypeName;
	}

	public void setDefaultPrimaryTypeName(String defaultPrimaryTypeName) {
		this.defaultPrimaryTypeName = defaultPrimaryTypeName;
	}

	public boolean isAllowsSameNameSiblings() {
		return isAllowsSameNameSiblings;
	}

	public void setAllowsSameNameSiblings(boolean isAllowsSameNameSiblings) {
		this.isAllowsSameNameSiblings = isAllowsSameNameSiblings;
	}

}
